package com.cyyz.tai.service;

import com.cyyz.tai.dao.DashStatsDao;
import com.cyyz.tai.model.DashStats;
import com.vteba.common.service.impl.DefaultServiceImpl;
import com.vteba.tx.dao.impl.HibernateDaoImpl;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import jakarta.transaction.Transactional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.List;

@Named
@Transactional
public class DashStatsService extends DefaultServiceImpl<DashStats, String> {
    private static final Logger LOGGER = LogManager.getLogger(DashStatsService.class);

    private static final String sql = "select count(*) value1, defect_type from dash_stats where states = ? group by defect_type";

    private DashStatsDao dashStatsDao;

    // public List<DashStats> query(DashStats query) {
    //     return dashStatsDao.queryList(query);
    // }

    @Inject
    @Override
    public void setBasicDao(HibernateDaoImpl<DashStats, String> dashStatsDao) {
        this.hibernateDao = dashStatsDao;
        this.dashStatsDao = (DashStatsDao) dashStatsDao;
    }

    // public void save(DashStats dashStats) {
    //     dashStatsDao.save(dashStats);
    // }

    // public void saveBatch(List<DashStats> dashStatsList) {
    //     // 5000条数据，加上反射也只需要330毫秒，性能还是OK的
    //     // long d = System.currentTimeMillis();
    //     dashStatsDao.saveBatch(dashStatsList);
    //     // Prints.println(System.currentTimeMillis() - d);
    // }

    public DashStats get(String id) {
        return dashStatsDao.get(id);
    }

    public DashStats unique(DashStats dashStats) {
        return dashStatsDao.uniqueResult(dashStats);
    }

    public List<DashStats> queryCountList(Integer states) {
        // SQL关键字使用小写，在栏位别名检测时，使用的是小写
        List<DashStats> dashStatsList = dashStatsDao.queryListSQL(sql, states);
        return dashStatsList;
    }
}
